﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XnaCanvas;
using color = Microsoft.Xna.Framework.Color;
using matrix = Microsoft.Xna.Framework.Matrix;

namespace Test.Scenes {
    public partial class XnaObj2Test2 : UserControl {
        public XnaObj2Test2() {
            InitializeComponent();
            this.Loaded += XnaObj2Test1_Loaded;
        }
        XSence xs;
        void XnaObj2Test1_Loaded(object sender, RoutedEventArgs e) {
            xs = this.xcanvas.Children[xcanvas.Trigger.Csn];
            xs.RefreshState += xs_RefreshState;
            xs.diffuseColor = color.White;
            var xo1 = xs.Add("polygon", new XObj2()) as XObj2;
            var xo2 = xs.Add("circle", new XObj2()) as XObj2;
            xo1.SetColor(0, 250, 0, 200);
            xo2.SetColor(0, 250, 0, 200);
            var ps = XObject.Get2(-.5f, -.5f, .5f, -.5f, 0, .5f);
            var transf = matrix.CreateRotationX(MathHelper.PiOver4);
            var transf2 = matrix.CreateTranslation(0, 1.5f, 0);
            var transf3 = transf * matrix.CreateTranslation(0, -.5f, 0);
            xo1.LoadRectangle();
            xo2.LoadRectangle();
            xo1.Transform(transf2);
            xo2.Transform(transf3);
            //xo2.World = matrix.CreateTranslation(2, 2, 0);
            //xo1.World = matrix.CreateTranslation(-2, -2, 0);
            xcanvas.Begin();
        }

        void xs_RefreshState(object sender, RefreshStateArgs e) {
            foreach (var item in e.result) {
                item.Value.World *= matrix.CreateRotationX(.01f);
                item.Value.World *= matrix.CreateRotationY(.01f);
                item.Value.World *= matrix.CreateRotationZ(.01f);
            }
        }
    }
}
